home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 52
/
Volume 52 - JOGO DISK .iso
/
Games
/
skipandgouls.swf
/
scripts
/
__Packages
/
sarbakan
/
utils
/
PerformanceWatcher.as
< prev
next >
Wrap
Text File
|
2007-10-01
|
6KB
|
133 lines
class sarbakan.utils.PerformanceWatcher
{
static var DEBUG_DEPTH = 123456;
static var DEBUG_RIGHT_MARGIN = 0;
static var DEBUG_TOP_MARGIN = 0;
static var DEBUG_FONT = "Verdana";
static var DEBUG_FONT_SIZE = 10;
static var DEBUG_FONT_COLOR = 16777215;
static var DEBUG_FONT_SHADOW_COLOR = 0;
static var aListeners = new Array();
function PerformanceWatcher()
{
}
static function start(l_nMovieFPS)
{
sarbakan.utils.PerformanceWatcher.nMovieFPS = l_nMovieFPS;
if(!sarbakan.utils.PerformanceWatcher.bActive)
{
sarbakan.utils.PerformanceWatcher.bActive = true;
mx.transitions.OnEnterFrameBeacon.init();
sarbakan.utils.PerformanceWatcher.oEnterFrameListener = new Object();
sarbakan.utils.PerformanceWatcher.oEnterFrameListener.onEnterFrame = mx.utils.Delegate.create(sarbakan.utils.PerformanceWatcher,sarbakan.utils.PerformanceWatcher.update);
MovieClip.addListener(sarbakan.utils.PerformanceWatcher.oEnterFrameListener);
}
sarbakan.utils.PerformanceWatcher.nCurrentFPS = sarbakan.utils.PerformanceWatcher.nMovieFPS;
sarbakan.utils.PerformanceWatcher.reset();
}
static function stop()
{
if(sarbakan.utils.PerformanceWatcher.bActive)
{
sarbakan.utils.PerformanceWatcher.bActive = false;
MovieClip.removeListener(sarbakan.utils.PerformanceWatcher.oEnterFrameListener);
sarbakan.utils.PerformanceWatcher.stopDebug();
}
}
static function addListener(l_listener, l_nMinFPS, l_bDelete)
{
sarbakan.utils.PerformanceWatcher.aListeners.push({listener:l_listener,nMinFPS:l_nMinFPS,bDelete:l_bDelete});
}
static function removeListener(l_listener)
{
for(var _loc2_ in sarbakan.utils.PerformanceWatcher.aListeners)
{
if(sarbakan.utils.PerformanceWatcher.aListeners[_loc2_].listener == l_listener)
{
sarbakan.utils.PerformanceWatcher.aListeners.splice(_loc2_,1);
}
}
}
static function get fps()
{
return sarbakan.utils.PerformanceWatcher.nCurrentFPS;
}
static function startDebug(l_mcTimeline)
{
sarbakan.utils.PerformanceWatcher.mcDebug = l_mcTimeline.createEmptyMovieClip("PerformanceWatcherDebug",sarbakan.utils.PerformanceWatcher.DEBUG_DEPTH);
sarbakan.utils.PerformanceWatcher.mcDebug._x = Stage.width - sarbakan.utils.PerformanceWatcher.DEBUG_RIGHT_MARGIN - 50;
sarbakan.utils.PerformanceWatcher.mcDebug._y = sarbakan.utils.PerformanceWatcher.DEBUG_TOP_MARGIN;
sarbakan.utils.PerformanceWatcher.mcDebug.createTextField("field",2,0,0,50,50);
var _loc1_ = new TextFormat();
_loc1_.font = sarbakan.utils.PerformanceWatcher.DEBUG_FONT;
_loc1_.size = sarbakan.utils.PerformanceWatcher.DEBUG_FONT_SIZE;
_loc1_.color = sarbakan.utils.PerformanceWatcher.DEBUG_FONT_COLOR;
_loc1_.align = "right";
sarbakan.utils.PerformanceWatcher.mcDebug.field.setNewTextFormat(_loc1_);
sarbakan.utils.PerformanceWatcher.mcDebug.field.selectable = false;
sarbakan.utils.PerformanceWatcher.mcDebug.createTextField("fieldShadow",1,1,1,50,50);
var _loc2_ = new TextFormat();
_loc2_.font = sarbakan.utils.PerformanceWatcher.DEBUG_FONT;
_loc2_.size = sarbakan.utils.PerformanceWatcher.DEBUG_FONT_SIZE;
_loc2_.color = sarbakan.utils.PerformanceWatcher.DEBUG_FONT_SHADOW_COLOR;
_loc2_.align = "right";
sarbakan.utils.PerformanceWatcher.mcDebug.fieldShadow.setNewTextFormat(_loc2_);
sarbakan.utils.PerformanceWatcher.mcDebug.fieldShadow.selectable = false;
}
static function stopDebug()
{
if(sarbakan.utils.PerformanceWatcher.mcDebug != undefined)
{
sarbakan.utils.PerformanceWatcher.mcDebug.removeMovieClip();
}
}
static function update()
{
if(++sarbakan.utils.PerformanceWatcher.nUpdateCount == sarbakan.utils.PerformanceWatcher.nMovieFPS)
{
sarbakan.utils.PerformanceWatcher.computeFrameRate();
sarbakan.utils.PerformanceWatcher.updateDebug();
sarbakan.utils.PerformanceWatcher.notifyListeners();
}
}
static function reset()
{
sarbakan.utils.PerformanceWatcher.nUpdateCount = 0;
sarbakan.utils.PerformanceWatcher.nLastGetTimer = getTimer();
}
static function computeFrameRate()
{
var _loc1_ = getTimer() - sarbakan.utils.PerformanceWatcher.nLastGetTimer;
var _loc2_ = _loc1_ / 1000;
sarbakan.utils.PerformanceWatcher.nCurrentFPS = Math.round(sarbakan.utils.PerformanceWatcher.nMovieFPS / _loc2_);
sarbakan.utils.PerformanceWatcher.reset();
}
static function notifyListeners()
{
var _loc1_ = new Array();
for(var _loc2_ in sarbakan.utils.PerformanceWatcher.aListeners)
{
if(sarbakan.utils.PerformanceWatcher.aListeners[_loc2_].nMinFPS >= sarbakan.utils.PerformanceWatcher.nCurrentFPS)
{
sarbakan.utils.PerformanceWatcher.aListeners[_loc2_].listener(sarbakan.utils.PerformanceWatcher.nCurrentFPS);
if(sarbakan.utils.PerformanceWatcher.aListeners[_loc2_].bDelete)
{
_loc1_.push(sarbakan.utils.PerformanceWatcher.aListeners[_loc2_].listener);
}
}
}
for(_loc2_ in _loc1_)
{
sarbakan.utils.PerformanceWatcher.removeListener(_loc1_[_loc2_]);
}
}
static function updateDebug()
{
if(sarbakan.utils.PerformanceWatcher.mcDebug != undefined)
{
sarbakan.utils.PerformanceWatcher.mcDebug.field.text = sarbakan.utils.PerformanceWatcher.nCurrentFPS + " fps";
sarbakan.utils.PerformanceWatcher.mcDebug.fieldShadow.text = sarbakan.utils.PerformanceWatcher.nCurrentFPS + " fps";
}
}
}